package com.zyms.consumer;

import com.taobao.api.ApiException;
import com.zyms.SMSTools;
import com.zyms.module.sms.SMSBase;
import com.zyms.module.sms.SMSResult;
import com.zyms.myRunTime.MyRunTimeExcption;
import com.zyms.service.Base.BaseService;
import org.apache.commons.lang.SerializationUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;


/**
 * Created by Baggio on 2018-1-30.
 */
public class SMSconsumer extends BaseService implements MessageListener {
    public SMSconsumer() {
        System.out.println("----------------------------------------------");
        logger.info("SMSconsumer is start................");
    }

    public void onMessage(Message message) {
       /* logger.info("Message message===》》》"+message);*/
        System.out.println("Message message===》》》" + message.toString());
        System.out.println("getBody\n");
        System.out.println(message.getBody().toString());
        Object object = SerializationUtils.deserialize(message.getBody());
        //接收队列消息发送短信

       /* SMSRegedit smsRegedit=new SMSRegedit();
        smsRegedit.setCode(map.get("code"));
        smsRegedit.setPhone(map.get("phone"));*/

        try {
            SMSResult smsResult = SMSTools.sendSMS((SMSBase) object);
            System.out.println(smsResult.getErrorCode());
            System.out.println(smsResult.getErrorMSG());
        } catch (ApiException e) {
            e.printStackTrace();

        } catch (MyRunTimeExcption e) {
            e.printStackTrace();

        } catch (Exception e) {
            e.printStackTrace();

        }


    }
}
